#ifndef CX_LIB_LIST_H
#define CX_LIB_LIST_H
#include "cx_typedef.h"
#ifdef USE_DYNAMIC_MALLOC
#include "cx_heap.h"
#endif
typedef struct cx_slist_item
{
    struct cx_slist_item *next;
    cx_pointer_t content;
}cx_slist_item_t;

typedef struct cx_slist
{
    struct cx_slist_item * head;
    struct cx_slist_item * tail;
}cx_slist_t;

#define CX_SLIST_ITEM_HEAD \
struct cx_slist_item *next

typedef struct cx_list_item
{
    struct cx_list_item_t *pre;
    struct cx_list_item_t *next;
    cx_pointer_t content;
}cx_list_item_t;

#define CX_LIST_ITEM_HEAD \
struct cx_list_item_t *pre; \
struct cx_list_item_t *next;


typedef struct cx_list
{
    struct cx_list_item_t *head;
    struct cx_list_item_t *tail;
}cx_list_t;

#ifdef USE_DYNAMIC_MALLOC
cx_slist_t * cx_slist_create(void);
cx_slist_item_t* cx_slist_item_create(void);
cx_slist_item_t * cx_slist_item_free_all(cx_slist_t *list);
cx_slist_item_t * cx_slist_free(cx_slist_t *list, cx_slist_item_t* item);
#else
void cx_slist_init(cx_slist_t *plist);
void cx_slist_item_init(cx_slist_item_t *psitem, cx_pointer_t pconponent);
cx_slist_item_t * cx_slist_item_delete(cx_slist_t *list, cx_slist_item_t *item);
#endif
cx_slist_item_t * cx_slist_append(cx_slist_t * list, cx_slist_item_t*item);
cx_slist_item_t * cx_slist_preappend(cx_slist_t * list, cx_slist_item_t *item);
cx_slist_item_t * cx_slist_insert(cx_slist_item_t*pre, cx_slist_item_t* item);
cx_slist_item_t * cx_slist_seek(cx_slist_t *list, int num);


/*Double Linkeed List, havn't complete*/
#ifdef USE_DYNAMIC_MALLOC
cx_list_t * cx_list_create(void);
cx_list_item_t* cx_list_item_create(void);
cx_list_item_t *cx_list_free(cx_list_t *list, cx_list_item_t *item);
cx_list_item_t *cx_list_destroy(cx_list_t *list);
#else
void cx_list_init(cx_slist_t *list);
void cx_list_item_init(cx_slist_item_t *list);
#endif
cx_list_item_t *cx_list_append(cx_list_t * list, cx_list_item_t *item);
cx_list_item_t *cx_list_preappend(cx_list_item_t *list, cx_list_item_t *item);
cx_list_item_t *cx_list_insert(cx_list_item_t *pre, cx_list_item_t *item);
cx_list_item_t *cx_list_seeK(cx_list_t *list, int num);



#endif
